package com.clstu.list;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Vector;

public class ListExercise02 {
    public static void main(String[] args) {
        List list = new ArrayList();
        //List list = new LinkedList();
       // List list = new Vector();


        list.add(new Book("红楼梦","曹雪芹",100));
        list.add(new Book("西游记","吴承恩",10));
        list.add(new Book("水浒传","施耐庵",80));
        list.add(new Book("三国演义","罗贯中",90));
        for(Object obj:list){
            System.out.println(obj);
        }
        sort(list);
        System.out.println("=======排序后=======");
        for(Object obj:list){
            System.out.println(obj);
        }
    }

    public static void sort(List list){
        for (int i = 0; i < list.size()-1; i++) {
            for (int j = 0; j < list.size()-i-1; j++) {
                Book b1=(Book) list.get(j);
                Book b2=(Book) list.get(j+1);
                if(b1.getPrice()>b2.getPrice()){
                    list.set(j,b2);
                    list.set(j+1,b1);
                }
            }
        }
    }
}
class Book{
    private String name;
    private String author;
    private double price;
    public Book(String name,String author,double price){
        this.name=name;
        this.author=author;
        this.price=price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    @Override
    public String toString() {
        return
                "名称  " + name + '\'' +"   "+
                "价格  " + author + '\'' +"   "+
                "作者  " + price;
    }
}